package com.cse210.grocerwe.client;
import org.restlet.client.resource.Result;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;

import java.util.ArrayList;

public class GrocerWeProxy {
	
    private final ProxyA resourceA = GWT.create(ProxyA.class);
    private final ProxyB resourceB = GWT.create(ProxyB.class);
    private final ProxyC resourceC = GWT.create(ProxyC.class);
    private final ProxyD resourceD = GWT.create(ProxyD.class);
    private final ProxyE resourceE = GWT.create(ProxyE.class);
    private final ProxyF resourceF = GWT.create(ProxyF.class);
    private final ProxyG resourceG = GWT.create(ProxyG.class);
    private final ProxyH resourceH = GWT.create(ProxyH.class);
    private final ProxyI resourceI = GWT.create(ProxyI.class);
    
    public GrocerWeProxy()
    {
        
    }
    
    //Interface A
    public void getAllItems( String user, Result<SItem[]> callback )
    {
        resourceA.getClientResource().setReference("/android/interfaceA/"+user);
        resourceA.getAllItems(callback);
    }
    public void addItem(SItem item,Result<Void> callback)
    {
    	resourceA.getClientResource().setReference("/android/interfaceA/none");
    	resourceA.addItem(item, callback);
    }
    
    //Interface B
    public void getGroups(String user,Result<SGroup[]> callback)
    {
    	resourceB.getClientResource().setReference("/android/interfaceB/"+user);
    	resourceB.getGroups(callback);
    }
    
    public void editItem(SItem item,Result<Void> callback)
    {
    	resourceB.getClientResource().setReference("/android/interfaceB/none");
    	resourceB.editItem(item, callback);
    }
    
    //Interface C
    public void retrieveList(String group, Result<SItem[]> callback)
    {
    	resourceC.getClientResource().setReference("/android/interfaceC/"+group);
    	resourceC.retrieveList(callback);
    }
    public void createList(String user,SGroup group,Result<Void> callback)
    {
    	resourceC.getClientResource().setReference("/android/interfaceC/none");
    	resourceC.createList(user, group, callback);
    }
    
    //Interface D
    public void invite(SGroup group, String user, Result<Void> callback)
    {
    	resourceD.getClientResource().setReference("/android/interfaceD/");
    	resourceD.invite(group, user, callback);
    }
    
    //Interface E
    public void leaveGroup(String groupKey, String user, Result<Void> callback)
    {
    	resourceE.getClientResource().setReference("/android/interfaceE/");
    	resourceE.leaveGroup(groupKey, user, callback);
    }
    
    //Interface F
    //Sets isLocked to not null
    public void claimList(String groupKey, String user, Result<Void> callback)
    {
    	resourceF.getClientResource().setReference("/android/interfaceF/");
    	resourceF.claimList(user+"~"+groupKey,user+"~"+groupKey, callback);
    }
    
    //Interface G
    public void purchaseItems(ArrayList<SItem>items, Result<Void> callback)
    {
    	resourceG.getClientResource().setReference("/android/interfaceG/");
    	resourceG.purchaseItems(items, callback);
    }
    
    //Interface H
    //Sets isLocked to null
    public void releaseList(String groupKey, String user, Result<Void> callback)
    {
    	resourceH.getClientResource().setReference("/android/interfaceH/");
    	resourceH.releaseList(user+"~"+groupKey, user+"~"+groupKey, callback);
    }
    
    public void removeItem(String itemKey, Result<Void> callback)
    {
    	resourceI.getClientResource().setReference("/android/interfaceI/");
    	resourceI.removeItem(itemKey, callback);
    }
}
